//
// Created by Administrator on 12/5/2022.
//

#ifndef __BSP_H
#define __BSP_H

#include "main.h"

#define ADC_VAL_LEN 128
#define ADC_CH_CURR ADC_CHANNEL_0
#define ADC_CH_VBUS ADC_CHANNEL_1
#define ADC_CH_EXT ADC_CHANNEL_6
#define COM_BUFF_MAX 128

/* 全局内存资源 */
extern uint32_t ADC_VAL[ADC_VAL_LEN];
extern uint32_t g_voltRawBuffer[ADC_VAL_LEN / 2];
extern uint32_t g_currRawBuffer[ADC_VAL_LEN / 2];
extern uint8_t RX_BUFF[COM_BUFF_MAX];
extern uint8_t RX_BUFF_MIRROR[COM_BUFF_MAX];
extern uint8_t TX_BUFF[COM_BUFF_MAX];
extern float g_voltVal;
extern uint32_t g_voltRaw;
extern float g_currVal;
extern uint32_t g_currRaw;
extern int g_isPwrOn;
/* 外部软件组件 */
extern algoLinearCalib g_caliberVolt;
extern algoLinearCalib g_caliberCurr;
extern algoFilterSmooth g_voltFilter;
extern algoFilterSmooth g_currFilter;
extern drvDigitalTube g_drvTubeVol;
extern drvDigitalTube g_drvTubeCurr;

void configChannel(uint32_t ch);

#define PKG_HEAD "PKGHEAD"
#define PKG_DATA_SIZE 48

typedef struct digitubeFrm // 48 bytes
{
    uint8_t channel;
    long currValue;
}digitubeFrm;

void packPkg(pkg* src);
int LOG(const char *initStr, ...);
void writeROM(const uint8_t* data, uint32_t length);
void ReadROM(uint8_t* dst, uint32_t len);
uint8_t validPkg(const pkg* s);
int InitBsp(void);
int StartBsp(void);
void BspReport(void);

#endif //__BSP_H
